package com.example.administrator.hqq.adapter.discover;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.example.administrator.hqq.R;
import com.example.administrator.hqq.activity.mine.AmendUserDataActivity;
import com.example.administrator.hqq.bean.post.MyGroupListBean;
import com.example.administrator.hqq.utils.BoldTextUtils;
import com.example.administrator.hqq.utils.transform.GlideCircleTransform;
import com.zhy.autolayout.AutoLinearLayout;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @name: HQQ
 * @describe:
 * @author: 康海涛 QQ2541849981
 * @time: 2019/3/13 14:42
 * @remark:
 */
public class ReleasePostAddGroupListAdapter extends BaseAdapter {
    private Context context;
    private List<MyGroupListBean.DataBean> data;

    public ReleasePostAddGroupListAdapter(Context context, List<MyGroupListBean.DataBean> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view==null)
        {
            view = LayoutInflater.from(context).inflate(R.layout.release_forum_add_group_item, null);
            viewHolder=new ViewHolder(view);
            view.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) view.getTag();
        }
        Glide.with(context).load(data.get(i).getUrl()).bitmapTransform(new GlideCircleTransform(context)).into(viewHolder.groupImage);
        viewHolder.groupTitle.setText(data.get(i).getTitle());
        BoldTextUtils.BoldText(viewHolder.groupTitle);
        viewHolder.peopleNumber.setText(data.get(i).getMember_amount()+"");
        viewHolder.groupIntroduce.setText(data.get(i).getIntroduction());
        viewHolder.ageNumber.setText(data.get(i).getSame_age_count() + "");
        viewHolder.locationNumber.setText(data.get(i).getSame_city_count() + "");
        if (data.get(i).getSame_age_count()==0)
        {
            viewHolder.locationAuto.setVisibility(View.GONE);
        }else{
            viewHolder.locationAuto.setVisibility(View.VISIBLE);
        }
        if (data.get(i).getSame_city_count()==0)
        {
            viewHolder.ageAuto.setVisibility(View.GONE);
        }else{
            viewHolder.ageAuto.setVisibility(View.VISIBLE);
        }
        return view;
    }

    static class ViewHolder {
        @BindView(R.id.group_image)
        ImageView groupImage;
        @BindView(R.id.group_title)
        TextView groupTitle;
        @BindView(R.id.people_number)
        TextView peopleNumber;
        @BindView(R.id.number_auto)
        AutoLinearLayout numberAuto;
        @BindView(R.id.group_introduce)
        TextView groupIntroduce;
        @BindView(R.id.age_number)
        TextView ageNumber;
        @BindView(R.id.age_auto)
        AutoLinearLayout ageAuto;
        @BindView(R.id.location_number)
        TextView locationNumber;
        @BindView(R.id.location_auto)
        AutoLinearLayout locationAuto;
        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
